package com.example.myapplication.activity.live_activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.example.myapplication.R;

public class ActionUriActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_action_uri);
        findViewById(R.id.btn_dial).setOnClickListener(this);
        findViewById(R.id.btn_sms).setOnClickListener(this);
        findViewById(R.id.btn_my).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        String phoneNo = "12345";
        Intent intent = new Intent();
        if (view.getId() == R.id.btn_dial) {
            Log.i("MyTAG", "intent:btn_dial ");
            //打电话的动作
            intent.setAction(Intent.ACTION_DIAL);
            //声明某动作的Uri
            Uri uri = Uri.parse("tel:" + phoneNo);
            intent.setData(uri);
            startActivity(intent);
        } else if (view.getId() == R.id.btn_sms) {
            Log.i("", "intent:btn_sms ");
            //发短信的动作
            intent.setAction(Intent.ACTION_SENDTO);
            //声明某动作的Uri
            Uri uri = Uri.parse("smsto:" + phoneNo);
            intent.setData(uri);
            startActivity(intent);
        } else if (view.getId() == R.id.btn_my) {
            /*
            在其他的应用设置：<intent-filter>
            <actionandroid:name="android.intent.action.xx"/>
            <categoryandroid:name="android.intent.category.DEFAULT"/>
            </intent-filter>
             */
            intent.setAction("我自己的另一个应用的Android.intent.action.xx");
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            startActivity(intent);
        } else {
            Log.i("MyTAG", "啥也不是~~");
        }
    }
}